<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<%
	request.setAttribute("modelConfigPath", "cargo");
%>
<%@ include file="/WEB-INF/views/shared/master/contentHeader.jsp"%>
<style type="text/css">
	.template{display:none}
</style>
	
<t:panel cssClass="panel-flat form-detailed" customBody="true" customHead="true">
	<div class="detailed-navbar-content panel-body">
		<t:form modelAttribute="cargo" action="/cargo/cargo/save" method="post" cssClass="form-horizontal">
			<div class="hide">
				 <t:hidden path="cargoId"/>
 				 <t:hidden path="deleteMark"/>	
 				 <t:hidden path="createUserName"/>
		 		 <t:hidden path="createUserId"/>
		 		 <t:hidden path="createDate"/>
		 		 <t:hidden path="shopId"/>
		 		 <input type="hidden" value='${standardUsersJson}' id=standardUsersJson  />
			</div>
            <t:formgroup>
                <t:label path="cargoNo" cssClass="col-sm-1" />
                <t:input path="cargoNo" colClass="col-sm-2" />
                <t:label path="cargoName" cssClass="col-sm-1" />
                <t:input path="cargoName" colClass="col-sm-2" />
                <t:label path="unit" cssClass="col-sm-1" />
               <t:select2 allowClear="true" placeholder="选择单位" path="unit" colClass="col-sm-2" />
                <t:label path="categoryName" cssClass="col-sm-1" />
                <t:select2 allowClear="true" placeholder="选择分类" path="categoryName" colClass="col-sm-2" />
          
            </t:formgroup>
            <t:formgroup>
            	<t:label path="cargoType" cssClass="col-sm-1" />
                <t:select2 allowClear="true" placeholder="选择商品类型" path="cargoType" colClass="col-sm-2" />
                <t:label path="shapeCode" cssClass="col-sm-1" />
                <t:input path="shapeCode" colClass="col-sm-2" />
                <t:label path="describes" cssClass="col-sm-1" />
                <t:textarea  path="describes" colClass="col-sm-5"/>     
  
            </t:formgroup>
            
  <div class="table-responsive  " style="height:335px;overflow-x: hidden"> 
     <h6 style="margin-left:20px" class="content-group text-semibold">
		商品图片
	</h6>
	<div class="row">
	
		<c:forEach var="picture" items="${cargo.pictures}" varStatus="status">
			<c:if test="${picture.fileId!=null }">
				<div class="col-lg-2 col-md-2 col-sm-2">
				
					<div class="thumbnail">
						<div class="thumb">
							<img src="${tfile:getImageUrl(picture.fileId)}"  alt="" style="opacity: 0.7; height:145px;width:168px">
							<div class="caption-overflow">
								<span>
								 	<a href="${tfile:getImageUrl(picture.fileId)}" data-popup="lightbox" rel="gallery" class="btn border-white text-white btn-flat btn-icon btn-rounded"><i class="icon-eye">预览</i></a>
									<a onclick="deletePicture(this,'${picture.pictureId}')" href="#" class="btn border-white text-white btn-flat btn-icon btn-rounded ml-5"><i class="icon-bin" >删除</i></a>
								</span>
							</div>
						</div>
					</div>
					
				</div>
			</c:if>
		</c:forEach>
		<div  class="col-lg-2 col-md-2 col-sm-2" style="border-style:dotted;border-width:1px;width:158px">
			<t:button style="height:145px;width:138px;" onclick="addPicture()" cssClass="btn-link">添加图片</t:button>
		</div>
		</div>
	
		
	</div>
        
           
            <div class="form-group">

				<div class="col-md-12 col-sm-12 " style="text-align:right;margin: 0px;">
					<c:if test="${t_type ne 3}">
						<t:button icon="icon-floppy-disk" laddaType="progress"  onclick="saveData()" cssClass="btn-primary" csize="sm">保存</t:button>
					</c:if>
				</div>
		    </div>	
		    <div   id="addProduct" ></div>
		</t:form>
	</div>
	
</t:panel>

   

<script type="text/javascript">
$(function() {

	// Switchery toggle
    var elems = Array.prototype.slice.call(document.querySelectorAll('.switch'));
    elems.forEach(function(html) {
		var switchery = new Switchery(html);
    });


    // Styled checkboxes/radios
    $('.styled').uniform();


    // Image lightbox
    $('[data-popup="lightbox"]').fancybox({
	    padding: 3
    });

});

function deletePicture(element,id){
	console.log(id+"胡茂树")
	$(element).parent().parent().parent().parent().parent().remove();
	
	
	 var url =$.getVirtualPath()+"/cargo/cargo/deletePictures";
	 $.ajax({
	        type: 'post',
	        dataType: "json",
	        url: url,
	        data: "key="+id,
	        async: false,
	        success: function (result) {
	        			
	        	$.showTips(result.message,1000,result.resultType);	
	        	location.reload();
	        }
	    });		
}

function addPicture(){
	var cargoId=$("#cargoId").val();
	console.log(cargoId)
	$("#uploaded").uploadFile({multi_selection:true,FileUploaded:function(up, file, info){
		
		if(info.status==200){
			
			var responseJson=JSON.parse(info.response);
			
			if(responseJson.status=="ok"){
				
				var pictureId=responseJson.id;
				
				 var url =$.getVirtualPath()+"/cargo/cargo/addPictures";
				 $.ajax({
				        type: 'post',
				        dataType: "json",
				        url: url,
				        data: "pictureIds="+pictureId+"&cargoId="+cargoId,
				        async: false,
				        success: function (result) {
				        			
				        	$.showTips(result.message,1000,result.resultType);	
				        	location.reload();
				        }
				    });							
		 	}		
			
		}	
	}
});
}

function saveData(lBtn){
	if (!$("form:first").valid()){
		return;
	}
	lBtn.start();
	$("form:first").submit();
}	


</script>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formstyling.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/media.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/jqueryui.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/uploaders/uploaders.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/uploadFile.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formpickers.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formbuttons.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formstyling.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formselects.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/dialog.jsp"%>
<%@ include file="/WEB-INF/views/shared//master/contentFooter.jsp"%>